﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AvvaMobileNHibernateHelperKit.Objects
{
    public partial class ErrorListWindow : UserControl
    {
        public ErrorListWindow()
        {
            InitializeComponent();
        }

        bool showProcess = true;
        bool hideOutput = false;
        int wait = 0;

        public DataTable ErrorList
        {
            set
            {
                DataTable dtErrors = ((DataTable)value);
                foreach (DataRow dr in dtErrors.Rows)
                {
                    ListViewItem item = new ListViewItem(dr["ErrorType"].ToString(), 0);
                    item.SubItems.Add(dr["Description"].ToString());
                    item.SubItems.Add(dr["ProjectName"].ToString());
                    listErrors.Items.Add(item);

                }
                ShowOutput();
            }
        }

        public void ShowOutput()
        {
            timer.Enabled = true;
        }

        public void HideOutput()
        {
            showProcess = false;
            this.ShowOutput();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            if (showProcess == true)
            {
                if (this.Height <= 300)
                {
                    this.Height += 20;
                    this.Location = new Point(this.Left, this.Top - 20);
                }
                else
                {
                    timer.Enabled = false;
                }
            }
            else
            {
                if (wait >= 50 && hideOutput == true)
                {
                    if (this.Height >= 1)
                    {
                        this.Height -= 20;
                        this.Location = new Point(this.Left, this.Top + 20);
                    }
                    else
                    {
                        this.Height = 0;
                        timer.Enabled = false;
                        showProcess = true;
                        wait = 0;
                    }
                }
                else
                {
                    wait += 1;
                }
            }
        }
        
        private void Output_MouseLeave(object sender, EventArgs e)
        {
            hideOutput = true;
            
            if(hideOutput == true)
            {
                HideOutput();
            }
        }

        private void OutPutWindow_MouseEnter(object sender, EventArgs e)
        {
            wait = 0;
            hideOutput = false;
        }

        private void imgExitButton_Click(object sender, EventArgs e)
        {
            wait = 50;
            hideOutput = true;
            showProcess = false;
            timer.Enabled = true;
        }

        private void ErrorListWindow_Resize(object sender, EventArgs e)
        {
            this.listErrors.Columns[1].Width = this.Width - 150 - 60;
        }










    }
}
